package store.controller;

import store.dao.CategoryDAO;
import store.dao.GoodsDAO;
import store.po.Category;
import store.po.Goods;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/goods/edit")
public class EditGoods extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        Goods g=new Goods();
        g.setId(Integer.parseInt(request.getParameter("id")));
        g.setName(request.getParameter("name"));
        g.setSpecs(request.getParameter("specs"));
        g.setSn(request.getParameter("sn"));
        g.setPrice(Double.parseDouble(request.getParameter("price")));
        g.setCategoryId(Integer.parseInt(request.getParameter("category_id")));

        try {
            new GoodsDAO().update(g);
            request.getRequestDispatcher("/goods/list").forward(request,response);
        } catch (Exception e) {
            e.printStackTrace();
            throw new RuntimeException(e.getMessage());
        }
    }

}
